<template>
  <div class="search-result-container">
    <!-- 点击实现后退效果 -->
    <van-nav-bar
      title="搜索结果"
      left-arrow
      @click-left="$router.go(-1)"
      fixed
    />
    <div>
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
        offset="1"
      >
        <Articleitem
          v-for="obj in list"
          :key="obj.art_id"
          :artObj="obj"
          :closeShow="false"
        ></Articleitem>
      </van-list>
    </div>
  </div>
</template>

<script>
import { searchApi } from '@/api'
import Articleitem from '@/components/ArticleItem'
export default {
  data () {
    return {
      list: [],
      finished: false, // 没有数据之后显示
      loading: false, // 默认不显示加载
      page: 1 // 默认要第一页的数据
    }
  },
  name: 'SearchResult',
  methods: {
    async getList () {
      const [, res] = await searchApi({
        q: this.$route.params.kw,
        page: this.page
      })
      if (res.data?.data?.results?.length === 0) {
        this.finished = true
      }
      //   console.log(res)
      this.list = [...this.list, ...res.data.data.results]
      this.loading = false
    },
    onLoad () {
      this.getList()
      this.page++
    }
  },
  components: {
    Articleitem
  }
}
</script>

<style lang="less" scoped>
.search-result-container {
  padding-top: 46px;
}
</style>
